import type {
  IQueryChat,
  IQueryGetChatMessage,
  IQueryUpdateChatTitle,
  IResponseChatList,
  IResponseChatMessage,
  IResponseCreateChat,
} from '@/interface/api';
import request from '@/utils/request';

/**
 * 查询对话列表
 * @param data
 * @returns
 */
export const queryChatList = (): Promise<IResponseChatList> => {
  return request({
    method: 'get',
    url: '/user_get_conversation_list/',
  });
};

/**
 * 创建对话
 * @param data
 * @returns
 */
export const createChat = (): Promise<IResponseCreateChat> => {
  return request({
    method: 'post',
    url: '/user_create_conversation/',
  });
};

/**
 * 修改对话标题
 */
export const updateChatTitle = (data: IQueryUpdateChatTitle): Promise<any> => {
  return request({
    method: 'post',
    url: '/user_update_conversation_title/',
    data,
  });
};

/**
 * 删除对话
 * @param data
 * @returns
 */
export const deleteChatApi = (data: IQueryChat): Promise<any> => {
  return request({
    method: 'delete',
    url: '/user_delete_conversation/',
    data,
  });
};

/**
 * 获取对话历史聊天记录
 * @param data
 * @returns
 */
export const getChatMessageHistory = (
  data: IQueryGetChatMessage
): Promise<IResponseChatMessage> => {
  return request({
    method: 'get',
    url: '/user_get_conversation_message/',
    params: data,
  });
};

/**
 * 保存聊天记录
 * @param data
 * @returns
 */
export const saveChatMessageHistory = (data: IQueryChat): Promise<IResponseChatMessage> => {
  return request({
    method: 'post',
    url: '/user_save_conversation_message/',
    data,
  });
};

/**
 * 聊天
 * @param data
 * @returns
 */
export const chatWithAI = (data: IQueryChat): Promise<IResponseChatMessage> => {
  return request({
    method: 'post',
    url: '/user_multi_round_dialogue/',
    data,
  });
};
